﻿
Imports osi.root.constants
Imports osi.root.envs

Namespace constants
    Public Module _constants
        Public ReadOnly use_socket As Boolean = True

        Sub New()
            use_socket = Not (env_bool(env_keys("donot", "use", "socket")) OrElse
                              env_bool(env_keys("do", "not", "use", "socket")))
        End Sub
    End Module

    Namespace default_value
        Namespace incoming
            Public Module _incoming
                Public Const max_connecting As UInt32 = max_uint32
                Public Const max_connected As UInt32 = max_uint32
                Public Const max_lifetime_ms As Int64 = 24 * 60 * 60 * second_milli
            End Module
        End Namespace

        Namespace outgoing
            Public Module _outgoing
                Public Const connecting_timeout_ms As Int64 = 10 * second_milli
                Public Const max_connecting As UInt32 = 2
                Public Const max_connected As UInt32 = 256
                Public Const max_lifetime_ms As Int64 = npos
            End Module
        End Namespace

        Public Module _default_value
            Public Const buff_size As Int32 = 4096
            Public Const response_timeout_ms As Int64 = 30 * second_milli
            Public Const send_rate_sec As UInt32 = 1
            Public Const receive_rate_sec As UInt32 = 1
            Public Const no_delay As Boolean = False
            Public Const ipv4 As Boolean = True
            Public Const enable_keepalive As Boolean = True
            Public Const first_keepalive_ms As UInt32 = 8 * second_milli
            Public Const keepalive_interval_ms As UInt32 = 8 * second_milli
        End Module
    End Namespace

    Namespace interval_ms
        Public Module _interval_ms
            Public ReadOnly watch_expiration As Int64 = 5 * second_milli
            Public ReadOnly watch_connectivity As Int64 = 15 * second_milli
            Public ReadOnly answer_powerpoint_change As Int64 = 5 * second_milli
            Public ReadOnly connector_fail As Int64 = 1 * second_milli
            Public ReadOnly connector_check As Int64 = 100
            Public ReadOnly accepter_over_max_connecting As Int64 = 100

            Sub New()
                If Not (env_value(env_keys("tcp", "watch", "expiration", "interval", "ms"),
                                  watch_expiration) OrElse
                        env_value(env_keys("tcp", "watch", "expiration"),
                                  watch_expiration)) OrElse
                   watch_expiration <= 0 Then
                    watch_expiration = 5 * second_milli
                End If
                If Not (env_value(env_keys("tcp", "watch", "connectivity", "interval", "ms"),
                                  watch_connectivity) OrElse
                        env_value(env_keys("tcp", "watch", "connectivity"),
                                  watch_connectivity)) OrElse
                   watch_connectivity <= 0 Then
                    watch_connectivity = 15 * second_milli
                End If
                If Not (env_value(env_keys("tcp", "answer", "powerpoint", "change", "interval", "ms"),
                                  answer_powerpoint_change) OrElse
                        env_value(env_keys("tcp", "answer", "powerpoint", "change"),
                                  answer_powerpoint_change)) OrElse
                   answer_powerpoint_change <= 0 Then
                    answer_powerpoint_change = 5 * second_milli
                End If
                If Not (env_value(env_keys("tcp", "connector", "fail", "interval", "ms"),
                                  connector_fail) OrElse
                        env_value(env_keys("tcp", "connector", "fail"),
                                  connector_fail)) OrElse
                   connector_fail <= 0 Then
                    connector_fail = 1 * second_milli
                End If
                If Not (env_value(env_keys("tcp", "connector", "check", "interval", "ms"),
                                  connector_check) OrElse
                        env_value(env_keys("tcp", "connector", "check"),
                                  connector_check)) OrElse
                   connector_check <= 0 Then
                    connector_check = 100
                End If
                If Not (env_value(env_keys("tcp", "accepter", "over", "max", "connecting", "interval", "ms"),
                                  accepter_over_max_connecting) OrElse
                        env_value(env_keys("tcp", "accepter", "over", "max", "connecting"),
                                  accepter_over_max_connecting)) OrElse
                   accepter_over_max_connecting <= 0 Then
                    accepter_over_max_connecting = 100
                End If
            End Sub
        End Module
    End Namespace
End Namespace
